package com.superman.supermarket.client.activity;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.mvp.IPageView;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.mvp.ShopAbstractActivity;
import com.superman.supermarket.client.view.search.GoodsSearchView;
import com.superman.supermarket.client.view.search.GoodsSearchView.GoodsSearchViewPresenter;

/**
 * 商品搜索
 * 
 * @author superman
 * @version 2018年8月2日下午5:08:48
 */
public class GoodsSearchActivity extends ShopAbstractActivity implements GoodsSearchViewPresenter {

	@Inject
	GoodsSearchView goodsSearchView;

	@Override
	public IPageView getView() {
		return goodsSearchView;
	}

	@Override
	public IPageViewPresenter getViewPresenter() {
		return this;
	}

	@Override
	public void onActivity(EventBus eventBus) {
	}

	@Override
	public void popToRefresh() {
		// TODO Auto-generated method stub
	}

	@Override
	public void popToRefresh(Object contextData) {
		// TODO Auto-generated method stub

	}

	@Override
	public void pushToRefresh() {
	}

	@Override
	public void searchByKeyWords(String keywords) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("SEARCH_KEY", keywords);
		map.put("PAGE_INDEX", 1);
		map.put("PAGE_CAPACITY", 20);

		postman.post("goods/list/bySearch", map, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onBusinessOK(String response) {
				if (XJsonUtil.getCount(response) == 0)
					goodsSearchView.setSearchReusltList(null);
				else
					goodsSearchView.setSearchReusltList(XJsonUtil.getList(response));
			}
		});
	}

}
